package com.pll.controller.user;

import com.pll.controller.admin.user.vo.MerchantSettledVO;
import com.pll.controller.admin.user.vo.MerchantLoginVO;
import com.pll.controller.admin.user.vo.MerchantRegistrationVO;
import com.pll.dto.ResponseDto;
import com.pll.service.CaptchaService;
import com.pll.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @className: UserController
 * @author: XR_Z
 * @date: 2025/6/7 18:22
 * @Version: 1.0
 * @description: 用户
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private CaptchaService captchaService;

    /**
     * 商家登录
     * @param loginVO 商家登录VO
     * @return dto
     */
    @PostMapping("/login")
    public ResponseDto login(@RequestBody MerchantLoginVO loginVO, HttpServletRequest request) {
        return userService.login(loginVO, request);
    }

    /**
     * 商家注册
     * @param merchantRegistrationVO 商家注册信息
     * @return dto
     */
    @PostMapping("/enroll")
    public ResponseDto enroll(@RequestBody MerchantRegistrationVO merchantRegistrationVO) {
        return userService.enroll(merchantRegistrationVO);
    }

    /**
     * 验证码生成
     * @param response 当前请求的http
     */
    @GetMapping("/captcha")
    public void captcha(HttpServletResponse response, HttpServletRequest request){
        try {
            captchaService.createCaptcha(response,request);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    /**
     * 商家入驻
     * @param merchantSettledVO 商家入驻VO
     * @return dto
     */
    public ResponseDto merchantSettled(MerchantSettledVO merchantSettledVO) {

        return userService.merchantSettled(merchantSettledVO);
    }

}